package com.opentd.game;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.Vector;

import com.opentd.graphics.Drawable;
import com.opentd.npc.Tower;

public class Player implements Drawable{
	public int health;
	private boolean isFirst = true;
	private BufferedImage fullImage;
	public static Vector<Tower> towers = new Vector<Tower>();
	
	
	public Player(int health){
		this.health = health;
	}
	
	public void damage(int amount){
		health -= amount;
	}
	
	public void heal(int amount){
		health += amount;
	}
	
	public void logic(){
		if(isFirst){
			towers.add(new Tower(2, 4, 1));
			towers.add(new Tower(4, 6, 2));
			isFirst = false;
		}
		
		if(health <= 0){
			Game.selectedLevel.won = false;
			Game.State.currentScreen = Game.State.END_SCREEN;
		}
		
		for(Tower t : towers){
			t.logic();
		}
	}

	@Override
	public void draw(Graphics g) {
		fullImage = new BufferedImage(Game.selectedLevel.map.width * Game.Block.WIDTH,
				Game.selectedLevel.map.height * Game.Block.HEIGHT,
				BufferedImage.TRANSLUCENT);
		for(Tower t : towers){
			t.draw(fullImage.getGraphics());
		}
		g.drawImage(fullImage.getScaledInstance(Game.panel.getWidth(), Game.panel.getHeight() - Game.Levels.MAP_HEIGHT_IN_PIXELS, BufferedImage.SCALE_SMOOTH), 0, 0, Game.panel.getWidth(), Game.panel.getHeight() - Game.Levels.MAP_HEIGHT_IN_PIXELS, null);
	}
}
